package com.xy.mainp.novel.fragment.home.widget;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;

import com.xy.mainp.R;
import com.xy.mainp.databinding.ViewBookListBinding;
import com.xy.mainp.model.biqu.home.novellist.NovelListEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by John on 2016/12/13.
 */

public class BookListView extends FrameLayout {
    private List<NovelListEntity> data;
    private ViewBookListBinding binding;
    private ListView leftView;
    private RecyclerView cevView;

    public BookListView(Context context) {
        this(context,null);
    }

    public BookListView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public BookListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.view_book_list,this,true);
        leftView = new ListView(getContext());
        ViewGroup.LayoutParams Lp = leftView.getLayoutParams();
        leftView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        binding.sliderBookList.setLeftView(leftView);

        cevView = new RecyclerView(getContext());
        cevView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        binding.sliderBookList.setCevView(cevView);
        binding.sliderBookList.setLeftWidthPS(0.5f);
    }

    public void setData(List<NovelListEntity> data) {
        ArrayList<String> t = new ArrayList<>();
        for (int i=0;i<data.size();i++){
            String tittle = data.get(i).getNovelListTittle();
            t.add(tittle);
        }
        leftView.setAdapter(new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,t));
    }
}
